home *** CD-ROM | disk | FTP | other *** search
- Path: druid.borland.com!usenet
- From: pete@borland.com (Pete Becker)
- Newsgroups: comp.lang.c++
- Subject: Re: Bizzare C++ bug...PLEASE CHECK IT OUT
- Date: 17 Feb 1996 18:29:53 GMT
- Organization: Borland International
- Message-ID: <4g56r1$ep5@druid.borland.com>
- References: <4fsns9$8ga3@flute.aix.calpoly.edu>
- NNTP-Posting-Host: pbecker.borland.com
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=ISO-8859-1
- X-Newsreader: WinVN 0.99.5
-
- In article <4fsns9$8ga3@flute.aix.calpoly.edu>, mporcell@flute.aix.calpoly.edu
- says...
- >
- >Clearly the call to the overloaded operator<< (r2) at r4 will cause a crash
- >because it is a call from a base class constructor (B) to a virtual print
- >function (r1) that does not get defined until the derived class C (r5).
-
- Nope. Calling a virtual function in a constructor results in a call to the
- version of the function defined for that class. It does not call a "function
- that does not get defined until the derived class". It is perfectly legal,
- perfectly safe, and almost certainly incorrect.
-
- class A
- {
- public:
- virtual void f();
- };
-
- class B : public A
- {
- public:
- B();
- };
-
- class C : public B
- {
- public:
- virtual void f(); // overrides A::f()
- };
-
- B::B()
- {
- f(); // calls A::f, despite existence of C::f
- }
-
-
-